package com.example.qxfw.dataBaseManager.nyzjk.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.example.qxfw.common.entity.ny.CropGrowdateHistory;
import com.example.qxfw.common.entity.ny.CropGrowdateIndexlib;
import com.example.qxfw.common.entity.ny.CropyieldHistory;
import com.example.qxfw.common.entity.ny.StationInfo;
import com.example.qxfw.common.mapper.CropGrowDateIndexLibMapperXml;
import com.example.qxfw.common.mapper.CropGrowdateHistoryMapperXml;
import com.example.qxfw.common.mapper.CropYieldHistoryMapperXml;
import com.example.qxfw.common.mapper.StationInfoMapperXml;
import com.example.qxfw.dataBaseManager.nyzjk.service.FyqclzlkService;
import com.example.qxfw.nyqx.mapper.CropGrowdateIndexlibMapper;
import com.example.qxfw.rcyw.mapper.StationInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.List;

/************************************
 *
 * @author : HuangDeYin Jolly
 * @since : JDK 11
 * @Date : 2023/7/5  星期三   13:31
 * @description : 此类用来
 ***************************************/
@Service
public class FyqclzlkServiceImpl implements FyqclzlkService {

    @Autowired
    private StationInfoMapper stationInfoMapper;

    @Autowired
    private CropGrowdateIndexlibMapper cropGrowdateIndexlibMapper;

    @Autowired
    private CropGrowDateIndexLibMapperXml cropGrowDateIndexLibMapperXml;


    @Autowired
    private StationInfoMapperXml stationInfoMapperXml;

    @Autowired
    private CropGrowdateHistoryMapperXml cropGrowdateHistoryMapperXml;

    @Autowired
    private CropYieldHistoryMapperXml yieldHistoryMapperXml;

    @Override
    public List<StationInfo> selectStationId(StationInfo stationInfo,String order,Integer limit) {
        List<StationInfo> stationInfoList = this.stationInfoMapperXml.querySelect(stationInfo,order,limit);
        return stationInfoList;
    }

    @Override
    public List<CropGrowdateIndexlib> querySelect(String field,String cropName) {
        List<CropGrowdateIndexlib> cropGrowdateIndexlibList = this.cropGrowDateIndexLibMapperXml.querySelect(field, cropName);
        return cropGrowdateIndexlibList;
    }

    @Override
    public List<CropGrowdateHistory> selectCropGrowdateHistory(CropGrowdateHistory cropGrowdateHistory,String order,Integer limit) {
        List<CropGrowdateHistory> cropGrowdateHistoryList = this.cropGrowdateHistoryMapperXml.querySelect(cropGrowdateHistory, order, limit);
        return cropGrowdateHistoryList;
    }

    @Override
    public List<CropyieldHistory> selectCropYieldHistory(final CropyieldHistory cropyieldHistory, final String order, final Integer limit) {
        List<CropyieldHistory> cropyieldHistoryList = this.yieldHistoryMapperXml.querySelect(cropyieldHistory, order, limit);
        return cropyieldHistoryList;
    }

    @Override
    public Integer saveCropGrowdateHistory(final CropGrowdateHistory cropGrowdateHistory) {
        int insert = this.cropGrowdateHistoryMapperXml.insertSelective(cropGrowdateHistory);
        return insert;
    }

    @Override
    public Integer saveCropYieldHistory(final CropyieldHistory cropyieldHistory) {
        int insert = this.yieldHistoryMapperXml.insert(cropyieldHistory);
        return insert;
    }

    @Override
    public Integer updateCropGrowdateHistory(final CropGrowdateHistory cropGrowdateHistory) {
        CropGrowdateHistory cropGrowdateHistory1 = new CropGrowdateHistory();
        cropGrowdateHistory1.setStationid(cropGrowdateHistory.getStationid());
        cropGrowdateHistory1.setCropname(cropGrowdateHistory.getCropname());
        cropGrowdateHistory1.setType(cropGrowdateHistory.getType());
        cropGrowdateHistory1.setYear(cropGrowdateHistory.getYear());
        cropGrowdateHistory1.setGrowdatename(cropGrowdateHistory.getGrowdatename());
        cropGrowdateHistory1.setGrowdatedate(cropGrowdateHistory.getGrowdatedate());
        UpdateWrapper<CropGrowdateHistory> updateWrapper = new UpdateWrapper<>();
        updateWrapper
                .lambda()
                .eq(CropGrowdateHistory::getStationid, cropGrowdateHistory.getStationid())
                .eq(CropGrowdateHistory::getCropname, cropGrowdateHistory.getCropname())
                .eq(CropGrowdateHistory::getType, cropGrowdateHistory.getType())
                .eq(CropGrowdateHistory::getYear, cropGrowdateHistory.getYear())
                .eq(CropGrowdateHistory::getGrowdatename, cropGrowdateHistory.getGrowdatename());
        return this.cropGrowdateHistoryMapperXml.update(cropGrowdateHistory, updateWrapper);
    }

    @Override
    public Integer updateCropYieldHistory(final CropyieldHistory cropyieldHistory) {
        CropyieldHistory cropyieldHistory1 = new CropyieldHistory();
        cropyieldHistory1.setStationid(cropyieldHistory.getStationid());
        cropyieldHistory1.setCropname(cropyieldHistory.getCropname());
        cropyieldHistory1.setType(cropyieldHistory.getType());
        cropyieldHistory1.setYear(cropyieldHistory.getYear());
        cropyieldHistory1.setYield(cropyieldHistory.getYield());
        cropyieldHistory1.setHectare(cropyieldHistory.getHectare());
        UpdateWrapper<CropyieldHistory> updateWrapper = new UpdateWrapper<>();
        updateWrapper
                .lambda()
                .eq(CropyieldHistory::getStationid, cropyieldHistory.getStationid())
                .eq(CropyieldHistory::getCropname, cropyieldHistory.getCropname())
                .eq(CropyieldHistory::getType, cropyieldHistory.getType())
                .eq(CropyieldHistory::getYear, cropyieldHistory.getYear());

        return this.yieldHistoryMapperXml.update(cropyieldHistory,updateWrapper);
    }

    @Override
    public Integer deleteCropGrowdateHistory(final CropGrowdateHistory cropGrowdateHistory) {
        QueryWrapper<CropGrowdateHistory> queryWrapper = new QueryWrapper<>();
        queryWrapper
                .lambda()
                .eq(CropGrowdateHistory::getStationid, cropGrowdateHistory.getStationid())
                .eq(CropGrowdateHistory::getCropname, cropGrowdateHistory.getCropname())
                .eq(CropGrowdateHistory::getType, cropGrowdateHistory.getType())
                .eq(CropGrowdateHistory::getYear, cropGrowdateHistory.getYear())
                .eq(CropGrowdateHistory::getGrowdatename, cropGrowdateHistory.getGrowdatename())
                .eq(CropGrowdateHistory::getGrowdatedate, cropGrowdateHistory.getGrowdatedate());

        return this.cropGrowdateHistoryMapperXml.delete(queryWrapper);

    }

    @Override
    public Integer deleteCropYieldHistory(final CropyieldHistory cropyieldHistory) {
        QueryWrapper<CropyieldHistory> queryWrapper = new QueryWrapper<>();
        queryWrapper
                .lambda()
                .eq(CropyieldHistory::getStationid, cropyieldHistory.getStationid())
                .eq(CropyieldHistory::getCropname, cropyieldHistory.getCropname())
                .eq(CropyieldHistory::getType, cropyieldHistory.getType())
                .eq(CropyieldHistory::getYear, cropyieldHistory.getYear())
                .eq(CropyieldHistory::getYield, cropyieldHistory.getYield())
                .eq(CropyieldHistory::getHectare, cropyieldHistory.getHectare())
                .eq(CropyieldHistory::getUsername, cropyieldHistory.getUsername());
        return this.yieldHistoryMapperXml.delete(queryWrapper);
    }
}
